package com.mpgame.database.mysql.mapper.game;

import com.mpgame.database.mysql.mapper.BaseMapper;
import com.mpgame.database.mysql.model.game.SkillForm;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface SkillFormMapper extends BaseMapper<SkillForm> {
    
    @Insert("INSERT INTO skill_form (monster_id, skill_id, min_level) VALUES (#{monsterId}, #{skillId}, #{minLevel})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(SkillForm skillForm);

    @Select("SELECT * FROM skill_form WHERE id = #{id}")
    SkillForm selectById(@Param("id") int id);

    @Select("SELECT * FROM skill_form WHERE monster_id = #{monsterId}")
    List<SkillForm> selectByMonsterId(@Param("monsterId") int monsterId);

    @Select("SELECT * FROM skill_form WHERE skill_id = #{skillId}")
    List<SkillForm> selectBySkillId(@Param("skillId") int skillId);

    @Select("SELECT * FROM skill_form WHERE monster_id = #{monsterId} AND skill_id = #{skillId}")
    SkillForm selectByMonsterAndSkill(@Param("monsterId") int monsterId, @Param("skillId") int skillId);

    @Select("SELECT * FROM skill_form")
    List<SkillForm> selectAll();

    @Update("UPDATE skill_form SET min_level = #{minLevel} WHERE id = #{id}")
    int updateById(SkillForm skillForm);
}
